home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / QuickDraw™ FX / events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  6.7 KB  |  259 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    QuickDraw™ FX                                            */
  4. /*                                                                            */
  5. /*    Description:                                                            */
  6. /*                                                                            */
  7. /*    File:            events.c                                                */
  8. /*                                                                            */
  9. /*    Files:            FX.π                                                    */
  10. /*                    FX.π.rsrc                                                */
  11. /*                    FX.h                                                    */
  12. /*                    events.c                                                */
  13. /*                    main.c                                                    */
  14. /*                    menu.c                                                    */
  15. /*                                                                            */
  16. /*    Programmer:        Edgar Lee                                                */
  17. /*    Organization:    Apple Computer, Inc. ©1992                                */
  18. /*    Department:        Developer Technical Support, DTS                        */
  19. /*    Language:        C (Think C version 5.0.2)                                */
  20. /*    Date Created:    5-26-92                                                    */
  21. /*                                                                            */
  22. /****************************************************************************/
  23.  
  24. #include "FX.h"
  25.  
  26. void handleMouseDown();
  27.  
  28. void eventLoop()
  29. {
  30.     EventRecord     event;
  31.     WindowPtr        window;
  32.     short            clickArea;
  33.     Rect             screenRect;
  34.     long            sleep = 30;
  35.     Point            point;
  36.     
  37.     for (;;)
  38.     {        
  39.         if (WaitNextEvent( everyEvent, &event, sleep, (RgnHandle)nil ))
  40.         {
  41.             if (event.what == mouseDown)
  42.             {
  43.                 clickArea = FindWindow( event.where, &window );
  44.                 
  45.                 if (clickArea == inDrag)
  46.                 {
  47.                     screenRect = (**GetGrayRgn()).rgnBBox;
  48.                     DragWindow(window, event.where, &screenRect );
  49.                 }
  50.                 else if (clickArea == inGoAway)
  51.                 {
  52.                     if (TrackGoAway( window , event.where ))
  53.                         ExitToShell();
  54.                 }
  55.                 else if (clickArea == inMenuBar)
  56.                 {
  57.                     adjustMenus();
  58.                     handleMenu( MenuSelect( event.where ) );
  59.                 }
  60.                 else if (clickArea == inContent)
  61.                 {
  62.                     if (window != FrontWindow())
  63.                         SelectWindow( window );
  64.                     else
  65.                     {
  66.                         point = event.where;
  67.                         GlobalToLocal( &point );
  68.                         handleMouseDown( point );
  69.                     }
  70.                 }
  71.             }
  72.             else if (event.what == updateEvt)
  73.             {
  74.                 window = (WindowPtr)event.message;
  75.                 SetPort( window );
  76.                 
  77.                 BeginUpdate( window );
  78.                 updateWindow();
  79.                 EndUpdate( window );
  80.             }
  81.             else if (event.what ==  keyDown || event.what == autoKey)
  82.             {
  83.                 if ((event.modifiers & cmdKey) != 0)
  84.                 {
  85.                     adjustMenus();
  86.                     handleMenu( MenuKey( (char)(event.message & charCodeMask) ) );
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93. void handleMouseDown( point )
  94. Point    point;
  95. {
  96.     int        i;
  97.     long    ticks;
  98.     int        itemNum = -1;
  99.  
  100.     for (i = 0; i < numBItems; i++)
  101.         if (PtInRect( point, &bItem[i].rect ))
  102.         {
  103.             if (i == settings.bItem - 1)
  104.                 return;
  105.                 
  106.             drawItem( bItem[settings.bItem - 1].rect.left, bItem[settings.bItem - 1].rect.top,
  107.                                 &bItem[settings.bItem - 1].label, true, false );
  108.             drawItem( bItem[i].rect.left, bItem[i].rect.top,
  109.                                 &bItem[i].label, true, true );
  110.  
  111.             itemNum = 0;
  112.             settings.bItem = i + 1;
  113.             break;
  114.         }                
  115.  
  116.     if (gCurrentExample / 10 == transferID || gCurrentExample / 10 == customID)
  117.         for (i = 0; i < numTItems && itemNum == -1; i++)
  118.             if (PtInRect( point, &tItem[i].rect ))
  119.             {
  120.                 if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
  121.                 {
  122.                     drawItem( tItem[settings.tItem - 1].rect.left, tItem[settings.tItem - 1].rect.top,
  123.                                 &tItem[settings.tItem - 1].label, true, false );
  124.                     drawItem( tItem[i].rect.left, tItem[i].rect.top,
  125.                                 &tItem[i].label, true, true );
  126.                     
  127.                     itemNum = i + 1;
  128.                     settings.tItem = itemNum;
  129.                 }                
  130.                 break;
  131.             }
  132.         
  133.     if (gCurrentExample / 10 == arithmeticID || gCurrentExample / 10 == customID)            
  134.         for (i = 0; i < numAItems && itemNum == -1; i++)
  135.             if (PtInRect( point, &aItem[i].rect ))
  136.             {
  137.                 if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
  138.                 {
  139.                     drawItem( aItem[settings.aItem - 1].rect.left, aItem[settings.aItem - 1].rect.top,
  140.                                 &aItem[settings.aItem - 1].label, true, false );
  141.                     drawItem( aItem[i].rect.left, aItem[i].rect.top,
  142.                                 &aItem[i].label, true, true );
  143.                     
  144.                     itemNum = i + 1;
  145.                     settings.aItem = itemNum;
  146.                 }        
  147.                 break;
  148.             }
  149.     
  150.     if (gCurrentExample / 10 == colorizationID || gCurrentExample / 10 == customID)    
  151.         for (i = 0; i < numCItems && itemNum == -1; i++)
  152.             if (PtInRect( point, &cItem[i].rect ))
  153.             {
  154.                 if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
  155.                 {
  156.                     drawItem( cItem[settings.cItem - 1].rect.left, cItem[settings.cItem - 1].rect.top,
  157.                                 &cItem[settings.cItem - 1].label, true, false );
  158.                     drawItem( cItem[i].rect.left, cItem[i].rect.top,
  159.                                 &cItem[i].label, true, true );
  160.                     
  161.                     itemNum = i + 1;
  162.                     settings.cItem = itemNum;
  163.                 }
  164.                 break;
  165.             }
  166.         
  167.     if (gCurrentExample / 10 == ditherID || gCurrentExample / 10 == customID)
  168.         for (i = 0; i < numDItems && itemNum == -1; i++)
  169.             if (PtInRect( point, &dItem[i].rect ))
  170.             {
  171.                 if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
  172.                 {
  173.                     drawItem( dItem[settings.dItem - 1].rect.left, dItem[settings.dItem - 1].rect.top,
  174.                                 &dItem[settings.dItem - 1].label, true, false );
  175.                     drawItem( dItem[i].rect.left, dItem[i].rect.top,
  176.                                 &dItem[i].label, true, true );
  177.                     
  178.                     itemNum = i + 1;
  179.                     settings.dItem = itemNum;
  180.                 }
  181.                 break;
  182.             }
  183.     
  184.     if (gCurrentExample / 10 == searchProcID || gCurrentExample / 10 == customID)
  185.         for (i = 0; i < numMItems && itemNum == -1; i++)
  186.             if (PtInRect( point, &mItem[i].rect ))
  187.             {
  188.                 if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID)
  189.                 {
  190.                     drawItem( mItem[settings.mItem - 1].rect.left, mItem[settings.mItem - 1].rect.top,
  191.                                 &mItem[settings.mItem - 1].label, true, false );
  192.                     drawItem( mItem[i].rect.left, mItem[i].rect.top,
  193.                                 &mItem[i].label, true, true );
  194.                     
  195.                     itemNum = i + 1;
  196.                     settings.mItem = itemNum;
  197.                 }    
  198.                 break;
  199.             }
  200.  
  201.     if (gCurrentExample / 10 == paintBucketID)
  202.     {
  203.         Rect    rect;
  204.         void    paintBucketExample();
  205.         
  206.         SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37,
  207.                 (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );
  208.  
  209.         paintBucketExample( &rect, 0, point );
  210.     }
  211.     /*
  212.     if (gCurrentExample / 10 == lassoID)
  213.     {
  214.         Rect    rect;
  215.         Rect    frame;
  216.         void    lassoToolExample();
  217.         
  218.         frame.left = point.h;
  219.         frame.top = point.v;
  220.         
  221.         while( StillDown() )
  222.         {
  223.             GetMouse( &point );
  224.             frame.right = point.h;
  225.             frame.bottom = point.v;
  226.         }
  227.         
  228.         SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37,
  229.                 (*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );
  230.  
  231.         lassoToolExample( &rect, 0, &frame );
  232.     }
  233.     */
  234.     if (itemNum != -1)
  235.     {
  236.         if (itemNum == 0)
  237.         {
  238.             drawSourceImage();
  239.             ticks = drawFXImage();
  240.             drawTime( ticks );
  241.         }
  242.         else
  243.         {
  244.             if (gCurrentExample / 10 == customID)
  245.                 itemNum = gCurrentExample;
  246.             else
  247.                 itemNum = ((gCurrentExample / 10) * 10) + itemNum;
  248.                 
  249.             if (itemNum != gCurrentExample || itemNum / 10 == customID)
  250.             {
  251.                 gCurrentExample = itemNum;
  252.                 
  253.                 drawSourceImage();
  254.                 ticks = drawFXImage();
  255.                 drawTime( ticks );
  256.             }
  257.         }
  258.     }
  259. }